package com.hzhc.netty;

import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName: NettyConfig
 * @Description:
 * @version 1.0
 * @author: duanhm
 * @Date: 2021/04/28 14:00:15
 * 
 */
public class NettyConfig {
	/**
	 ** 定义一个channel组， 管理所有的channel GlobalEventExecutor.INSTANCE 是全局的事件执行器， 是一个单例
	 */
	private static ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);

	/**
	 * 存放用户与Chanel的对应信息，用于给指定用户发送消息
	 */
	private static ConcurrentHashMap<String, Channel> userChannelMap = new ConcurrentHashMap<>();

	public static String USERNAME = "userName";// 登入用户名称
	public static String DEVID = "devId";// 设备编号
	public static String USERID = "userId";// 登入用户id
	public static String DEVICENO = "deviceNo";// 登入用户id
	public static String MACHINEMAME = "machineMame";// 登入用户id
	public static String TYPE = "type";// 登入用户id

	private NettyConfig() {
	}

	/**
	 * 获取channel组
	 * 
	 * @return
	 */
	public static ChannelGroup getChannelGroup() {
		return channelGroup;
	}

	/**
	 * 获取用户channel map
	 * 
	 * @return
	 */
	public static ConcurrentHashMap<String, Channel> getUserChannelMap() {
		return userChannelMap;
	}
}
